<?php
namespace app\home\controller;
use app\common\controller\Home;
use think\Cache;	
class Star extends Home{
    public function show(){
		$param = zanpiancms_param_url();
		if($param['dir']){
			$param['id'] = getlist($param['dir'],'list_dir','list_id');
		}else{
			$param['dir'] = getlist($param['id'],'list_id','list_dir');
		}
        //config('params',array('id'=>$param['id'],'dir'=>$param['dir'],'p'=>'[PAGE]'));
		$info=$this->Lable_List($param);
		$this->assign('param',$param);
        return $this->fetch(DS.$info['list_skin']);			
    }
    public function type(){
		$param = zanpiancms_param_url();
		if($param['dir']){
			$param['id'] = getlist($param['dir'],'list_dir','list_id');
		}else{
			$param['dir'] = getlist($param['id'],'list_id','list_dir');
		}
        //config('params',array('id'=>$param['id'],'dir'=>$param['dir'],'sex'=>$param['sex'],'zy'=>$param['zy'],'area'=>$param['area'],'letter'=>$param['letter'],'order'=>$param['order'],'p'=>'[PAGE]'));
		$info=$this->Lable_List($param);
		$this->assign('param',$param);
		if ($this->request->isAjax()){
		    return $this->fetch(DS.$info['list_skin_type']."_ajax");
		}else{
		    return $this->fetch(DS.$info['list_skin_type']);
		}			
    }	
    public function read(){
		$param = zanpiancms_param_url();
        $array_detail = $this->get_cache_detail($param);
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail']);
		}
		abort(404,'内容不存在');
    }
    public function info(){
		$param = zanpiancms_param_url();
        $array_detail = $this->get_cache_detail($param);
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail'].'_info');
		}
		abort(404,'内容不存在');
    }	
    public function work(){
		$param = zanpiancms_param_url();
		if($param['vcid']){
			$param['vdir']=getlist($param['vcid'],'list_id','list_dir');
		}else{
			$param['vcid']=getlist($param['vdir'],'list_dir','list_id');
			
		}
		$array_detail = $this->get_cache_detail($param);
		config('params',array('id'=>$array_detail['read']['star_id'],'pinyin'=>$array_detail['read']['star_letters'],'cid'=>$array_detail['read']['star_cid'],'dir'=>$array_detail['show']['list_dir'],'vcid'=>$param['vcid'],'vdir'=>$param['vdir'],'p'=>"[PAGE]"));
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail'].'_work');
		}
		abort(404,'内容不存在');
    }
    public function hz(){
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_detail($param);
		config('params',array('id'=>$array_detail['read']['star_id'],'pinyin'=>$array_detail['read']['star_letters'],'cid'=>$array_detail['read']['star_cid'],'dir'=>$array_detail['show']['list_dir'],'p'=>"[PAGE]"));
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail'].'_hz');
		}
		abort(404,'内容不存在');
    }
    public function role(){
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_detail($param);
		config('params',array('id'=>$array_detail['read']['star_id'],'pinyin'=>$array_detail['read']['star_letters'],'cid'=>$array_detail['read']['star_cid'],'dir'=>$array_detail['show']['list_dir'],'p'=>"[PAGE]"));
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail'].'_role');
		}
		abort(404,'内容不存在');
    }
    public function news(){
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_detail($param);
		config('params',array('id'=>$array_detail['read']['star_id'],'pinyin'=>$array_detail['read']['star_letters'],'cid'=>$array_detail['read']['star_cid'],'dir'=>$array_detail['show']['list_dir'],'p'=>"[PAGE]"));
		if($array_detail){
		    $this->assign('param',$param);
			$this->assign('show',$array_detail['show']);
            $this->assign('info',$array_detail['read']);			
		    return $this->fetch(DS.$array_detail['read']['star_skin_detail'].'_news');
		}
		abort(404,'内容不存在');
    }	
   //从数据库获取数据
	private function get_cache_detail($param){
		if(empty($param['id']) && empty($param['pinyin'])){ return false;}
		//优先读取缓存数据
		if($GLOBALS['config']['cache']['data_cache_star']){
			$array_detail = Cache::get('data_cache_star_'.$param['id'].$param['pinyin']);
			if($array_detail){
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		if(!empty($param['id'])){
		    $where['star_id'] = $param['id'];
		}
		if(!empty($param['pinyin'])){
		    $where['star_letters'] = $param['pinyin'];
		}		
		$where['star_status'] = array('eq',1);
		$data = db('star')->where($where)->find();
		if(!empty($data)){
			//解析标签
			$array_detail = $this->Lable_Star_Read($data,3);
			if($GLOBALS['config']['cache']['data_cache_star']){
				Cache::tag('model_star')->set('data_cache_star_'.$param['id'].$param['pinyin'],$array_detail,intval($GLOBALS['config']['cache']['data_cache_star'])); 
			}
			return $array_detail;
		}
		abort(404,'内容不存在');
	}		
}
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
